﻿<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="SampleWebForms._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Welcome to IrishSettings!
    </h2>
    <p>
        This website will illustrate how to set up a settings schema and then vary settings by application, version and user.
    </p>
    <h2>
        Installation
    </h2>
    <p>
        Installation assumes SqlExpress is available and that the aspnetdb.mdb file can be successfully created.
    </p>
    <p>
        IrishSettings uses the Dataglot library and requires the following appSettings:
    </p>
    <p>
         InstallIrishSettings.CreateAllTables(string connectionStringName, string prefix)
         
    </p>
    <asp:Button runat="server" ID="InstallToDatabase" Text="Install Database Tables"/><br/>
    <asp:Button runat="server" ID="InitializeSettings" Text="Insert Settings Schema (names, types, default values, etc)"/>
    <h2>
        Current Settings
    </h2>
    <p>Settings intially start out at the default values.</p>
    <asp:GridView runat="server" ID="CurrentSettings">
        
    </asp:GridView>
    <h2>
        Editing Settings
    </h2>
    <p>
        We update the values table to update a particular value. Simple types are serialized as strings. Complex types are serialized with protobuf-net.
        Here is an example initial schema. If there is already another application, the two applications will not affect each other. If 
        there is already an application of the same name, but lower version in the database, then you have an upgrade scenario.
    </p>
    <code>
<pre>
    public class TestSettings : SettingsApplication
    {
        public TestSettings()
        {
            Construct(new Version(1, 0));
        }

        public TestSettings(Version v)
        {
            Construct(v);
        }

        private void Construct(Version v)
        {
            Application = "TestApp";
            CultureObject = new CultureInfo("en-US");
            VersionObject = v;
            Schema.ValidateAndAdd("culture", Schema.StringItem("culture", "en-US", CultureObject)); //is-is
            Schema.ValidateAndAdd("timezone", Schema.StringItem("timezone", "EST", CultureObject));
            Schema.ValidateAndAdd("fiscalStart", Schema.IntItem("fiscalStart", 10, CultureObject));
            Schema.ValidateAndAdd("workdayStart", Schema.IntItem("workdayStart", 8, CultureObject));
            Schema.ValidateAndAdd("workdayEnd", Schema.IntItem("workdayEnd", 16, CultureObject));
            Schema.ValidateAndAdd("earliestHitDate", Schema.StringItem("earliestHitDate", "1/1/2011", CultureObject));
        }
    }
</pre>    
    </code>
    <h2>
        Version Upgrade
    </h2>
    <p>
        In a version upgrade, new settings schema rows are inserted, then new values are created at defaults and where possible, the
        old values overwrite the new.
    </p>
    <h2>
        Sharing the settings table
    </h2>
    <p>
        The settings table can be shared across two or more applications.
    </p>
    <h2>
        User Settings
    </h2>
    <p>
        User settings are similar to ASP.NET Profile. IrishSettings uses IIdenitity.Name to distinguish users and will support anonymous users. 
    </p>
    <h2>Comparison to Existing APIs</h2>
    <p>ApplicationSettingsBase and the Configurations namespace in generally are awefully complicated. 
    And they are focused on datastores that are generally xml files on disk.</p>
    <p>Both ApplicationSettingsBase and Profile focus on a development experience that involves code generated files for 
    strongly typed access to settings values.</p>
    <p>Other settings APIs target .ini files, the windows registry and ad hoc xml. .ini is unstructure, windows registry is more and more unavailable 
    to applications due to security restrictions, and xml files on disk are treated by large organizations as part of the application and 
    changing them can involve lengthy waterfall processes that data in tables isn't subject to.</p>
</asp:Content>
